package cn.edu.lit.jsjxy.CourseExample.chapter3;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import cn.edu.lit.jsjxy.CourseExample.R;

public class MenuTestActivity extends Activity
{


    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu_test);

        listView = findViewById(R.id.lv3);

        registerForContextMenu(listView);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        /*menu.add("test1");
        menu.add("test2");
        menu.add("test3");

        menu.add(0,1,1,"test4");
        menu.add(0,2,3,"test5");

        menu.add(0,3,4,"test6");

        menu.add(0,4,2,"test7");*/

        MenuInflater menuInflater = getMenuInflater();

        menuInflater.inflate(R.menu.main, menu);

        return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        Toast.makeText(this, item.getItemId() + " is clicked!", Toast
                .LENGTH_SHORT).show();

        LinearLayout ll = findViewById(R.id.menu_top_layout);
        //LinearLayout ll =  findViewById(R.id.menu_top_layout);
        switch (item.getItemId()) {
            case R.id.item3:

                ll.setBackgroundColor(Color.RED);
                break;

            case R.id.item4:
                ll.setBackgroundColor(Color.YELLOW);
                break;

            case R.id.item5:
                ll.setBackgroundColor(Color.BLUE);
                break;

        }

        //        Toast.makeText(this, item.getItemId() + "  is clicked", Toast.LENGTH_LONG).show();

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
    {
        super.onCreateContextMenu(menu, v, menuInfo);

        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.contexmenu, menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item)
    {
        Toast.makeText(this, item.getTitle() + " is clicked", Toast
                .LENGTH_SHORT).show();
        return true;
    }
}
